<template>
    <div>
      <zh-table
          ref="appTable"
          title="已授权应用"
          :height="600"
          :url="VITE_FILE_API_URL+'fileAppClass0001'"
          :columns="state.tableColumn"
          :radio-config="{ trigger: 'row' }"
          :disabled="false"
          highlight-current-row
      >
        <template #op="{row}">
          <zh-button buttonType="del" @click="delAppClass(row)" >取消授权</zh-button>
        </template>
      </zh-table>
    </div>
</template>

<script lang="ts" setup name="fileAppClass">
import {FormInstance,ElMessageBox} from "element-plus";
const VITE_FILE_API_URL = import.meta.env.VITE_FILE_API_URL as string+'/doc/api/';

// ------------------变量区------------------------------
const props = defineProps({
  scrollHeight: {
    type: String,
    default: ''
  },
  displayFlag: {
    type: Boolean,
    default:false
  },
});
const appClassInfo = ref<any>({
});
const appTable=ref();

const state = reactive({
  dictData:[],
  queryParam:{fileClassCode:''},
  tableColumn:[
    {type: 'seq', width: 80, fixed: 'left', align: 'center', title: '序号'},
    {field: 'appClassId', title: '应用文件分类Id', fixed: 'left', visible: false, align: 'center', minWidth: 150},
    {field: 'appId', title: '应用id', fixed: 'left',  align: 'center', minWidth: 150},
    {field: 'appName', title: '应用名称', fixed: 'left',  align: 'center', minWidth: 150},
    {field: 'fileClassCode', title: '文件分类编码', fixed: 'left',  align: 'center', minWidth: 150},
    {field: 'fileClassTitle', title: '文件分类', fixed: 'left',  align: 'center', minWidth: 150},
    {field: 'expireDate', title: '过期日期', fixed: 'left',  align: 'center', minWidth: 150},
    {field: 'op', title: '操作',  align: 'center',fixed:'right',width:200,slots: {default: 'op'}},
  ]
});

//------------------初始化------------------------------
const params = {
  dictFields: 'status,flag',
};
$api.common.getBatchDict.post(params).then((res) => {
  state.dictData = res.result;
});




//--------------------------定义调用方法--------------------------------------------------
function setInitData(info) {
  if (info) {
    state.queryParam.fileClassCode=info.fileClassCode;
    appTable.value.query(state.queryParam);
  }
}

function queryRefresh(){
  appTable.value.query(state.queryParam);
}

//取消已授权的app应用
function delAppClass(row){
  ElMessageBox.confirm(
      '将取消对'+row.appName+'的授权',
      '提示',
      {
        confirmButtonText: '继续',
        type: 'warning',
        showCancelButton: false
      }
  ).then(() => {
    //根据id删除当前文件接口分类
    $api.common.fileSend.post('fileAppClass0006', {appClassId:row.appClassId}).then(() => {
      $messageBox.success('取消成功', '提示');
      queryRefresh();
    }).catch(() => {});
  });

}

//------------设置给父组件调用的数据/方法(组件)-----------
defineExpose({setInitData,appClassInfo,queryRefresh});
</script>
